//
//  ViewController.swift
//  TestDemo
//
//  Created by youmy on 2018/11/27.
//  Copyright © 2018 youmy. All rights reserved.
//

import UIKit
import ProductView

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        view.backgroundColor = UIColor.groupTableViewBackground
        
        let bundle = Bundle(for: YMProductView.classForCoder())
        
        let dic = resouceObjectFromBundle(fileName: "product.json", bundle: bundle)
        let model = GZAZJOrderDetailModel(fromDictionary: dic)
        
        let productV = YMProductView.nibView()
        productV.valueConfig(model: model)
        productV.originY = 50
        view.addSubview(productV)
        
        print("--->\(productV.frame)")
    }


    func resouceObjectFromFile(fileName: String) -> [String:Any] {
        
        let jsonPath = Bundle.main.path(forResource: fileName, ofType: nil)
        
        let data = try? Data(contentsOf: URL(fileURLWithPath: jsonPath!))
        
        if data != nil {
            let dic = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as! Dictionary<String, Any>
            return dic ?? [String: Any]()
        }
        return [String: Any]()
    }
    
    func resouceObjectFromBundle(fileName: String, bundle:Bundle) -> [String:Any] {
        
        let jsonPath = bundle.path(forResource: fileName, ofType: nil)
        
        let data = try? Data(contentsOf: URL(fileURLWithPath: jsonPath!))
        
        if data != nil {
            let dic = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as! Dictionary<String, Any>
            return dic ?? [String: Any]()
        }
        return [String: Any]()
    }
}

